from django.db import models
from pgZhSearch import BaseFullTextSearchModel


class Question(BaseFullTextSearchModel):
    class Meta:
        ordering = ['id']
        verbose_name_plural = verbose_name = '问题表'
        indexes = BaseFullTextSearchModel.Meta.indexes

    # 综合检索设置
    search_field_conf = {
        'wen_ti': 'A',
        'fen_lei_ming': 'B',
        'da_an_nei_rong': 'C',
    }

    # 检索权重配置
    search_weight_conf = {
        'A': 0.8,
        'B': 0.7,
        'C': 0.3,
    }

    search_rank__gte = 0.01        # 最小相关性

    fen_lei_ming = models.TextField(blank=True, null=True, verbose_name='分类名', db_column='分类名')
    wen_ti = models.TextField(blank=True, null=True, verbose_name='问题', db_column='问题')
    da_an_nei_rong = models.TextField(blank=True, null=True, verbose_name='答案内容', db_column='答案内容')
    download_times = models.IntegerField(default=0, blank=True, null=True, verbose_name='下载次数')
    view_times = models.IntegerField(default=0, blank=True, null=True, verbose_name='浏览次数')
    is_active = models.BooleanField(verbose_name="激活", blank=True, null=True, default=True)


class TestModel(BaseFullTextSearchModel):
    class Meta:
        ordering = ['id']
        verbose_name_plural = verbose_name = '测试表'
        indexes = BaseFullTextSearchModel.Meta.indexes

    # 综合检索设置
    search_field_conf = {
        'title': 'A',
        'content': 'B',
    }

    # 检索权重配置
    search_weight_conf = {
        'A': 0.8,
        'B': 0.3,
    }

    search_rank__gte = 0.1        # 最小相关性

    title = models.CharField(max_length=128, verbose_name="标题", blank=True, null=True)
    content = models.TextField(verbose_name="内容", blank=True, null=True)
    is_active = models.BooleanField(verbose_name="激活", blank=True, null=True, default=True)
    create_time = models.DateTimeField(verbose_name='创建时间', blank=True, null=True)
    create_date = models.DateField(verbose_name='创建日期', blank=True, null=True)



